Skip to content

feat: Migrate to flagsmith-common centralized logging#7050

Open
khvn26 wants to merge 2 commits intomainfrom
feat/logging-improvements
Open

feat: Migrate to flagsmith-common centralized logging#7050
khvn26 wants to merge 2 commits intomainfrom
feat/logging-improvements

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented Mar 26, 2026

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to Flagsmith/flagsmith-common#179

Will be ready for merge once Flagsmith/flagsmith-common#179 is merged and released.

Migrates logging setup from Django settings to flagsmith-common's setup_logging(), which runs before Django loads.

  • Set LOGGING_CONFIG = None to prevent Django from wiping setup_logging() configuration
  • Remove structlog.configure block (handled by flagsmith-common)
  • Remove util/logging.py (JsonFormatter, GunicornJsonCapableLogger now in flagsmith-common)
  • Remove GUNICORN_LOGGER_CLASS from .env-ci (default in flagsmith-common)
  • Remove PROMETHEUS_HISTOGRAM_BUCKETS setting (uses library defaults)
  • Pin flagsmith-common to feat/logging-improvements branch

Env vars to set

APPLICATION_LOGGERS=app,features,integrations,task_processor,app_analytics,webhooks,gunicorn
ACCESS_LOG_EXTRA_ITEMS={flagsmith.route}e
ACCESS_LOG_LOCATION=-

How did you test this code?

Tested with ghcr.io/flagsmith/flagsmith-api:pr-7050.

Generic format (LOG_FORMAT=generic):

2026-03-26T17:40:08.789198Z [info     ] Starting gunicorn 23.0.0       [gunicorn.error]
2026-03-26T17:40:08.789660Z [info     ] Listening at: http://0.0.0.0:8000 (1) [gunicorn.error]
2026-03-26T17:40:08.789718Z [info     ] Using worker: gthread          [gunicorn.error]
2026-03-26T17:40:08.792125Z [info     ] Booting worker with pid: 7     [gunicorn.error]
2026-03-26T17:40:08.854358Z [info     ] Booting worker with pid: 8     [gunicorn.error]
2026-03-26T17:40:08.872841Z [info     ] Booting worker with pid: 9     [gunicorn.error]
192.168.215.1 - - [26/Mar/2026:17:40:17 +0000] "GET /health/liveness/ HTTP/1.1" 200 16 "-" "curl/8.7.1" - -
  • Boot/error logs: structlog ConsoleRenderer with ISO timestamps, no ANSI in non-TTY
  • Access logs: pure CLF via Gunicorn's own handler

JSON format (LOG_FORMAT=json):

Boot logs:

{"timestamp": "2026-03-26T17:36:45.855679Z", "message": "Starting gunicorn 23.0.0", "levelname": "INFO", "logger_name": "gunicorn.error", "pid": 1, "thread_name": "MainThread"}

Access log (structured):

{"timestamp": "2026-03-26T17:36:54.266879Z", "time": "2026-03-26T17:36:54+00:00", "path": "/health/liveness/", "remote_ip": "192.168.215.1", "method": "GET", "status": "400", "user_agent": "curl/8.7.1", "duration_in_ms": 14, "response_size_in_bytes": 143, "message": "192.168.215.1 - - [26/Mar/2026:17:36:54 +0000] \"GET /health/liveness/ HTTP/1.1\" 400 143 \"-\" \"curl/8.7.1\" - -", "levelname": "INFO", "logger_name": "gunicorn.access", "pid": 7, "thread_name": "ThreadPoolExecutor-3_0"}

Django error log (also structured):

{"exc_info": ["<class 'django.core.exceptions.DisallowedHost'>", "..."], "timestamp": "2026-03-26T17:36:54.265623Z", "status_code": 400, "message": "Invalid HTTP_HOST header: '127.0.0.1:8001'...", "levelname": "ERROR", "logger_name": "django.security.DisallowedHost", "pid": 7, "thread_name": "ThreadPoolExecutor-3_0"}

- Replace LOGGING dict with no-op (setup_logging runs before Django)
- Remove structlog.configure block (handled by flagsmith-common)
- Remove util/logging.py (JsonFormatter, GunicornJsonCapableLogger
  now in flagsmith-common)
- Remove GUNICORN_LOGGER_CLASS from .env-ci (default in flagsmith-common)
- Remove PROMETHEUS_HISTOGRAM_BUCKETS setting (uses library defaults)
- Pin flagsmith-common to feat/logging-improvements branch
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Mar 26, 2026 5:00pm
flagsmith-frontend-preview Ignored Ignored Preview Mar 26, 2026 5:00pm
flagsmith-frontend-staging Ignored Ignored Preview Mar 26, 2026 5:00pm

Request Review

@github-actions github-actions bot added api Issue related to the REST API feature New feature or request labels Mar 26, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.33%. Comparing base (3f71f16) to head (3d813ba).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7050   +/-   ##
=======================================
  Coverage   98.33%   98.33%           
=======================================
  Files        1337     1335    -2     
  Lines       50010    49941   -69     
=======================================
- Hits        49178    49111   -67     
+ Misses        832      830    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@khvn26 khvn26 marked this pull request as ready for review March 26, 2026 16:36
@khvn26 khvn26 requested a review from a team as a code owner March 26, 2026 16:36
@khvn26 khvn26 requested review from Zaimwa9 and removed request for a team March 26, 2026 16:36
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.

Once credits are available, reopen this pull request to trigger a review.

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Mar 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-7050 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-7050 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-7050 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-7050 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-7050 Finished ✅ Results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  43.6 seconds
commit  da28717
info  🔄 Run: #15501 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  10.5 seconds
commit  da28717
info  🔄 Run: #15501 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  43.7 seconds
commit  da28717
info  🔄 Run: #15501 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 1 second
commit  da28717
info  🔄 Run: #15501 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  11.4 seconds
commit  3d813ba
info  🔄 Run: #15502 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  24.4 seconds
commit  3d813ba
info  🔄 Run: #15502 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  1 minute, 4 seconds
commit  3d813ba
info  🔄 Run: #15502 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  56.4 seconds
commit  3d813ba
info  🔄 Run: #15502 (attempt 1)

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant